package com.acme.bankapp.domain.bank;

import java.util.ArrayList;

import static com.acme.bankapp.service.bank.BankService.addAccount;
import static com.acme.bankapp.service.bank.BankService.addClient;

public class BankApplication {
	
	public void modifyBank(Bank bank, int idOfClient, String depositOrWithdraw, 
			int numOfAccount, int sum){
		
		ArrayList<Client> clients = bank.getClients();
		if(!(depositOrWithdraw.equals("deposit") || depositOrWithdraw.equals("withdraw")) 
				|| clients.size() < idOfClient + 1){
			System.out.println("Wrong format input data");
		}
		else if(clients.get(idOfClient).getAccounts().size() < numOfAccount + 1){
			System.out.println("Wrong format input data");
		}
		else{
			if(depositOrWithdraw.equals("deposit")){
				clients.get(idOfClient).getAccounts().get(numOfAccount).deposit(sum);
			}
			else if(depositOrWithdraw.equals("withdraw"))
				clients.get(idOfClient).getAccounts().get(numOfAccount).withdraw(sum);
		}
	}
	
	public void printBalance(Bank b){
		ArrayList<Client> clients = b.getClients();
		for (Client cl : clients){
			ArrayList<Account> accounts = cl.getAccounts();
			for(Account ac : accounts){
				cl.getClientSalutation();
				System.out.println(" " + ac.getBalance());
			}			
		}
	}
	
	public static void main(String[] args){
		
		BankApplication bankApplication = new BankApplication();
		Bank bank = new Bank();
		
		addClient(bank, new Client("Drozdov", Gender.MALE, 150, 50));
		addAccount(bank, 10, 120);
		
		System.out.println("Name: " + bank.getClients().get(10).getName());
		System.out.println("Gender: " + bank.getClients().get(10).getGender());
		System.out.println("Account 1, balance: " + 
				bank.getClients().get(10).getAccounts().get(0).getBalance());
		System.out.println("Account 2, balance: " + 
				bank.getClients().get(10).getAccounts().get(1).getBalance());
		System.out.println("After withdraw");
		
		bankApplication.modifyBank(bank, 10, "withdraw", 1, 75);
		
		System.out.println("Account 1, balance: " + 
				bank.getClients().get(10).getAccounts().get(0).getBalance());
		System.out.println("Account 2, balance: " + 
				bank.getClients().get(10).getAccounts().get(1).getBalance());
		
		bankApplication.modifyBank(bank, 10, "deposit", 0, 100);
		System.out.println("After deposit");
		
		System.out.println("Account 1, balance: " + 
				bank.getClients().get(10).getAccounts().get(0).getBalance());
		System.out.println("Account 2, balance: " + 
				bank.getClients().get(10).getAccounts().get(1).getBalance());
		
		bankApplication.printBalance(bank);
	}

}
